﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PropAndIndexersExample
{
    class Program
    {
        static void Main(string[] args)
        {
            IndexerExample example = new IndexerExample(-1);
            Console.WriteLine(example[0]);
        }
    }

    class IndexerExample
    {
        private int[] intArray;
        private int lenght;

        public IndexerExample(int arraySize)
        {

                Lenght = arraySize;
                intArray = new int[Lenght];
                for (int i = 0; i < Lenght; i++)
                {
                    intArray[i] = i + 1;
                }

        }

        public int Lenght
        {
            get { return lenght; }
            set
            {
                    if (value > 0)
                        lenght = value;
                    else
                    {
                        lenght = 1;
                    }
                
            }
        }

        public int this[int index]
        {
            get { return intArray[index]; }
            set { intArray[index] = value; }
        }




    }
}
